package com.weixin.weixinmanage.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.weixin.weixinmanage.entity.Account;

public class AccountAction extends ActionSupport{
	
	private Account account;

	/**
	 * 
	 */
	private static final long serialVersionUID = -4608936579616821638L;
	
	public String login(){
		Account sessionAccount = (Account)ActionContext.getContext().getSession().get(Account.ACCOUNT_SESSION);
		if(sessionAccount!=null){
			return "loginsuccess";
		}else{
			if(account==null){
				return "loginerror";
			}
			if(account.getAccountName().equals(Account.ACCOUNT_NAME)&&account.getAccountPassword().equals(Account.ACCOUNT_PASSWORD)){
				account.setAccountId(Account.ACCOUNT_ID);
				ActionContext.getContext().getSession().put(Account.ACCOUNT_SESSION, account);
				return "loginsuccess";
			}
		}
		return "loginerror";
	}
	
	public String logout(){
		ActionContext.getContext().getSession().remove(Account.ACCOUNT_SESSION);
		return "loginerror";
	}
	
	
	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}
	
}
